<!DOCTYPE html>
<html>
    <head>
        <title>#{get 'title' /}</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

        <link href="../../../public/stylesheets/style_sheet.css"
              rel="stylesheet" type="text/css" />
        <script type="text/javascript"
        src="/../../../public/javascripts/jquery.min.js"></script>
        <script type="text/javascript"
        src="/../../../public/javascripts/jquery-ui.min.js"></script>
        <script src="../../../public/javascript/jquery.js"
        type="text/javascript"></script>
        <script src="../../../public/javascript/scripts.js"
        type="text/javascript"></script>

        #{get 'moreStyles' /}
        <link rel="shortcut icon" type="image/png"
              href="@{'/public/images/ninjaIcon.png'}">
        <script type="text/javascript"
        src="@{'/public/javascripts/fancybox/jquery.fancybox-1.3.4.pack.js'}"></script>
        <link rel="stylesheet"
              href="@{'/public/javascripts/fancybox/jquery.fancybox-1.3.4.css'}"
              type="text/css" media="screen" />
        <link rel="stylesheet" href="../../../public/javascripts/jquery.jgrowl.css" type="text/css"/>

        <!-- JAVA SCRIPT PARTIOTION START -->

        <script type="text/javascript">
            //plugin found on the internet
            function updateList(){

                //Adjust panel height
                $.fn.adjustPanel = function() {
                    $(this).find("ul, .subpanel").css({
                        'height' : 'auto'
                    }); //Reset subpanel and ul height

                    var windowHeight = $(window).height(); //Get the height of the browser viewport
                    var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel
                    var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)
                    var ulAdjust = panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)

                    if (panelsub >= panelAdjust) { //If subpanel is taller than max height...
                        $(this).find(".subpanel").css({
                            'height' : panelAdjust
                        }); //Adjust subpanel to max height
                        $(this).find("ul").css({
                            'height' : ulAdjust
                        }); //Adjust subpanel ul to new size
                    } else if (panelsub < panelAdjust) { //If subpanel is smaller than max height...
                        $(this).find("ul").css({
                            'height' : 'auto'
                        }); //Set subpanel ul to auto (default size)
                    }
                };

                //Execute function on load
                $("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel
                $("#alertpanel").adjustPanel(); //Run the adjustPanel function on #alertpanel

                //Each time the viewport is adjusted/resized, execute the function
                $(window).resize(function() {
                    $("#chatpanel").adjustPanel();
                    $("#alertpanel").adjustPanel();
                });

                //Click event on Chat Panel + Alert Panel
                $("#chatpanel a:first, #alertpanel a:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...
                    if ($(this).next(".subpanel").is(':visible')) { //If subpanel is already active...
                        $(this).next(".subpanel").hide(); //Hide active subpanel
                        $("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
                    } else { //if subpanel is not active...
                        $(".subpanel").hide(); //Hide all subpanels
                        $(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
                        $("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
                        $(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
                    }
                    return false; //Prevent browser jump to link anchor
                });

                //Click event outside of subpanel
                $(document).click(function() { //Click anywhere and...
                    $(".subpanel").hide(); //hide subpanel
                    $("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
                });
                $('.subpanel ul').click(function(e) {
                    e.stopPropagation(); //Prevents the subpanel ul from closing on click
                });

                //Delete icons on Alert Panel
                $("#alertpanel li").hover(function() {
                    $(this).find("a.delete").css({
                        'visibility' : 'visible'
                    }); //Show delete icon on hover
                }, function() {
                    $(this).find("a.delete").css({
                        'visibility' : 'hidden'
                    }); //Hide delete icon on hover out
                });
            }

        </script>

        <script type="text/javascript">
            function showNotificationsNotification() {



                $
                .getJSON(
                '@{usersController.DisplayNotificationPopID()}',

                {
                    'userName' : "username"
                },
                function(data) {
                    if (data != null
                        && data.result == "sizeNotEqualZero" && data.NoNewNotification=="no") {

                        $('#two').jGrowl(data.list);

                    } else {


                        alert("No Notifications available ");						}
                });
            }
        </script>

        <script type="text/javascript">
            function showNotificationsID() {



                $
                .getJSON(
                '@{usersController.DisplayNotificationSID()}',

                {
                    'userName' : "username"
                },
                function(data) {
                    if (data != null
                        && data.result == "sizeNotEqualZero") {
                        var list = {};
                        list = data.list.split("&&");

                        var total = "<h3><span>&ndash; </span>Notifications</h3><ul><li class=\"view\"><a href=\"#\">View All</a></li>";
                        //<p><a href='#' onclick=\"show_iDev('"+ innerList[0]+ "')\">"+ innerList[0]+ "</a> "+innerList[1]+"</p>

                        for ( var i = 0; i < list.length-1 && i<5; i = i + 1) {

                            var innerList = {};
                            innerList = list[i].split(",,,");
                            total += "<li><a href=\"#\" class=\"delete\">X</a><p><a href='#' onclick=\"show_iDev('"+ innerList[0]+ "')\">"+ innerList[0]+ "</a> "+innerList[1]+"</p></li>";


                        }
                        total += "</ul>";
                        document.getElementById("notificationS").innerHTML = total;
                        updateList()
                    } else {
                        alert("No Notifications available ");						}
                });
            }
        </script>


        <script type="text/javascript">
            <!--
            var currrent = "";
            $(function() {
                $.getJSON("@{Application.getId()}",function(data){
                    current = data.res;
                });
                $('#createEntityDiv').hide();
                $('#createSubEntityDiv').hide();
                $('#deleteEntityDiv').hide();
                $('#orgRequestDiv').hide();
                $('#devRequestDiv').hide();
                $('#devCanDivInEnt').hide();
            });

            function OnGoMenuFormLink(GoList) {
                var url = GoList.options[GoList.selectedIndex].value;
                //var target = GoList.options[GoList.selectedIndex].className;
                if (url == "CreateEn") {
                    //prepare the data which is the organizations he can partiotion it
                    document.getElementById("createEntityDiv").innerHTML = "";
                    $
                    .getJSON(
                    '@{Application.getManagedOrganizations()}',
                    {
                        'id' : current
                    },
                    function(data) {
                        if (data == null || data.length == 0) {
                            alert("You arnot athurized to do that in any org :)");
                        } else {
                            alert(data.length)
                            var total = "<p><label>please choose one from your organizations</label><select id=\"selavorg\">"
                            for ( var i = 0; i < data.length; i = i + 1) {
                                total += "<option selected value="+data[i].id+">"
                                    + data[i].name + "</option>"
                            }
                            total += "</select></p>";
                            total += "<p><input type=\"text\" id=\"newEntName\"/></p>";
                            total += "<p><a href='#' onclick=\"createEntity()\">submit</a></p>";
                            document.getElementById("createEntityDiv").innerHTML = total;
                            $('#createEntityDiv').toggle(1000);
                            $('#createSubEntityDiv').hide(1000);
                            $('#deleteEntityDiv').hide(1000);
                            $('#orgRequestDiv').hide(1000);
                            $('#devRequestDiv').hide(1000);
                            $('#devCanDivInEnt').hide(1000);
                        }
                    });

                } else if (url == "CreateSub") {
                    $('#createSubEntityDiv').hide(1000);
                    document.getElementById("createSubEntityDiv").innerHTML = "";
                    $
                    .getJSON(
                    '@{Application.getManagedEntities()}',
                    {
                        'id' : current
                    },
                    function(data) {
                        if (data == null || data.length == 0) {
                            alert("You don't manage any entity to add a sub entity in :)");
                        } else {
                            var total = "<p><label>please choose one from your organizations</label><select id=\"selavent\">"
                            for ( var i = 0; i < data.length; i = i + 1) {
                                total += "<option selected value="+data[i].id+">"
                                    + data[i].name + "</option>"
                            }
                            total += "</select></p>";
                            total += "<p><input type=\"text\" id=\"newSubEntName\"/></p>";
                            total += "<p><a href='#' onclick=\"createSubEntity()\">submit</a></p>";
                            document
                            .getElementById("createSubEntityDiv").innerHTML = total;
                            $('#createEntityDiv').hide(1000);
                            $('#createSubEntityDiv').toggle(1000);
                            $('#deleteEntityDiv').hide(1000);
                            $('#orgRequestDiv').hide(1000);
                            $('#devRequestDiv').hide(1000);
                            $('#devCanDivInEnt').hide(1000);
                        }
                    });

                } else if (url == "DelEn") {
                    $('#deleteEntityDiv').hide(1000);
                    document.getElementById("deleteEntityDiv").innerHTML = "";
                    $
                    .getJSON(
                    '@{Application.getManagedEntities()}',
                    {
                        'id' : current
                    },
                    function(data) {
                        if (data == null || data.length == 0) {
                            alert("You don't manage any entity to delete it :)");
                        } else {
                            var total = "<p><label>please choose one from your entities</label><select id=\"selavent2\">"
                            for ( var i = 0; i < data.length; i = i + 1) {
                                total += "<option selected value="+data[i].id+">"
                                    + data[i].name + "</option>"
                            }
                            total += "</select></p>";
                            total += "<p><a href='#' onclick=\"delEntity()\">submit</a></p>";
                            document.getElementById("deleteEntityDiv").innerHTML = total;
                            $('#createEntityDiv').hide(1000);
                            $('#createSubEntityDiv').hide(1000);
                            $('#deleteEntityDiv').toggle(1000);
                            $('#orgRequestDiv').hide(1000);
                            $('#devRequestDiv').hide(1000);
                            $('#devCanDivInEnt').hide(1000);
                        }
                    });
                }else if(url == "CheckInviteOrg"){
                    $('#orgRequestDiv').hide();

                    $.getJSON("@{Application.getRequestsRecievedForMyOrgz()}",{'id':current},function(data){
                        if(data == null || data.length == 0){
                            alert("No New requests sent to join your organizations or your managed Entities");
                        }else{
                            document.getElementById("orgRequestDiv").innerHTML = "";
                            for(var i = 0 ; i < data.length ; i=i+1){
                                document.getElementById("orgRequestDiv").innerHTML += "<p>"+data[i].name+"<a href='#' onclick = \"acceptReq('"+data[i].id+"')\"> ACCEPT </a></p>";
                            }
                            $('#createEntityDiv').hide(1000);
                            $('#createSubEntityDiv').hide(1000);
                            $('#deleteEntityDiv').hide(1000);
                            $('#orgRequestDiv').toggle(1000);
                            $('#devRequestDiv').hide(1000);
                            $('#devCanDivInEnt').hide(1000);
                        }
                    });
                }else if(url == "CheckInviteDev"){
                    $('#devRequestDiv').hide();
                    $.getJSON("@{Application.getRequestsSentToIdeaDeveloper()}",{'devId':current},function(data){
                        if(data == null || data.length == 0){
                            alert("No New requests has been sent to you");
                        }else{
                            document.getElementById("devRequestDiv").innerHTML = "";
                            for(var i = 0 ; i < data.length ; i=i+1){
                                document.getElementById("devRequestDiv").innerHTML += "<p>"+data[i].name+"<a href='#' onclick = \"acceptReq('"+data[i].id+"')\"> ACCEPT </a></p>";
                            }
                            $('#createEntityDiv').hide(1000);
                            $('#createSubEntityDiv').hide(1000);
                            $('#deleteEntityDiv').hide(1000);
                            $('#orgRequestDiv').hide(1000);
                            $('#devRequestDiv').toggle(1000);
                            $('#devCanDivInEnt').hide(1000);
                        }
                    });
                }else if (url == "InviteDevToEntity") {
                    $('#devCanDivInEnt').hide(1000);
                    document.getElementById("devCanDivInEnt").innerHTML = "";
                    $
                    .getJSON(
                    '@{Application.getManagedEntities()}',
                    {
                        'id' : current
                    },
                    function(data) {
                        if (data == null || data.length == 0) {
                            alert("You don't manage any entity to join developers in :)");
                        } else {
                            //alert(data.length);
                            var total = "<p><label>please choose one from your entities</label><select id=\"selavent3\">"
                            for ( var i = 0; i < data.length; i = i + 1) {
                                total += "<option selected value="+data[i].id+">"
                                    + data[i].name + "</option>"
                            }
                            total += "</select></p>";
                            total += "<div id='ideaDevelopers'></div>";
                            total += "<p><a href='#' onclick=\"getDevCanReqInEnt()\">submit</a></p>";
                            document
                            .getElementById("devCanDivInEnt").innerHTML = total;
                            $('#devCanDivInEnt').toggle(1000);
                            $('#createEntityDiv').hide(1000);
                            $('#createSubEntityDiv').hide(1000);
                            $('#deleteEntityDiv').hide(1000);
                            $('#orgRequestDiv').hide(1000);
                            $('#devRequestDiv').hide(1000);
                        }
                    });


                }
            }

            function getDevCanReqInEnt(){
                var entId = document.getElementById('selavent3').options[document.getElementById('selavent3').selectedIndex].value
                document.getElementById('ideaDevelopers').innerHtml = "";
                $('#ideaDevelopers').hide(100);
                $.getJSON("@{Application.getCanRequestIdeaDevelopersToEntity()}",{'entId':entId},function(data){
                    if(data == null || data.length == 0){
                        alert("There are no developers you can invite to this entity");
                    }else{
                        var total = "";
                        for(var i = 0 ; i < data.length ; i=i+1){
                            if(data[i].id == -1){
                                total += "<p>"+data[i].name+"</p>";
                            }else{
                                total += "<p>"+data[i].name+" <a href='#' onclick=\"requestDeveloperInEntity('"+data[i].id+"','"+entId+"')\">Invite</a></p>";
                            }
                        }
                        document.getElementById("ideaDevelopers").innerHTML = total;
                        $('#ideaDevelopers').toggle(500);
                    }
                });
            }

            function requestDeveloperInEntity(devId,entId){
                $.getJSON("@{Application.requestIdeaDeveloperToEntity()}",{'devId':devId,'entId':entId},function(data){
                    alert(data.res);
                    getDevCanReqInEnt();
                });
            }
            function acceptReq(reqId){
                $.getJSON("@{Application.acceptRequest()}",{'reqId':reqId},function(data){
                    alert(data.res);
                });
            }

            function createEntity() {
                var orgid = document.getElementById('selavorg').options[document
                    .getElementById('selavorg').selectedIndex].value
                alert(current + "  " + orgid);
                if (document.getElementById("newEntName").value.length < 3) {
                    alert('name req and atleast 3');
                } else {
                    //public static void addEntity(String entityName, long orgId, long ideaDeveloper) {
                    $.getJSON('@{Application.addEntity()}', {
                        'entityName' : document.getElementById("newEntName").value,
                        'orgId' : orgid,
                        'ideaDeveloper' : current
                    }, function(data) {
                        alert(data.res);
                        if (data.res == "Done Adding") {
                            $('#createEntityDiv').toggle(1000);
                        }
                    });
                }

            }
            //public static void addSubEntity(String entityName, long entId, long ideaDeveloper)
            function createSubEntity() {
                if (document.getElementById("newSubEntName").value.length < 3) {
                    alert('name req and atleast 3');
                } else {
                    var orgid = document.getElementById('selavent').options[document
                        .getElementById('selavent').selectedIndex].value
                    $.getJSON('@{Application.addSubEntity()}', {
                        'entityName' : document.getElementById("newSubEntName").value,
                        'entId' : orgid,
                        'ideaDeveloper' : current
                    }, function(data) {
                        alert(data.res);
                        if (data.res == "Done Adding") {
                            $('#createSubEntityDiv').hide(1000);
                        }
                    });
                }
            }
            //public static void deleteEntity(long entId, long ideaDeveloper)
            function delEntity() {
                var orgid = document.getElementById('selavent2').options[document
                    .getElementById('selavent2').selectedIndex].value;
                $.getJSON('@{Application.deleteEntity()}', {
                    'entId' : orgid,
                    'ideaDeveloper' : current
                }, function(data) {
                    alert(data.res)
                    if (data.res == "DONE") {
                        $('#deleteEntityDiv').hide(1000);
                    }
                });
            }
        </script>


        <script type="text/javascript">
            $(document).ready(function() {
                //		$(".frame").fancybox({
                //
                //			'width' : '75%',
                //
                //			'height' : '75%',
                //
                //			'autoScale' : true,
                //
                //			'transitionIn' : 'none',
                //
                //			'transitionOut' : 'none',
                //
                //			'type' : 'iframe'


                //            });

                updateList()	});
        </script>
    </head>
    <body>
        <div id="container">
            <div id="header">
                <h1>
                    <a href="/">MEGASOFT</a>
                </h1>
                <h2>Software ninjas</h2>
                <div class="clear"></div>
            </div>
            <div id="nav">

            </div>
            
            <br/>
            <div id="createEntityDiv"></div>

            <div id="createSubEntityDiv"></div>

            <div id="deleteEntityDiv"></div>

            <div id="orgRequestDiv"></div>

            <div id="devRequestDiv"></div>

            <div id="devCanDivInEnt"></div>

            <div id="devCanDivInOrg"></div>




            <div id="page-intro"></div>


            <div id="body">

                <div id ="footerplacement"style="height:328px ;width:0px;float:right;"></div>
			#{doLayout /}
                <div class="clear"></div>
            </div>
        </div>
        <!-- Notification bar  start here -->
        <div id="footpanel">
            <ul id="mainpanel">
                <li><a href="#" class="profile">View
					Profile <small>View Profile</small> </a>
                </li>
                <li><a href="#" class="editprofile">Edit
					Profile <small>Edit Profile</small> </a>
                </li>
                <li><a href="#" class="contacts">Contacts
                        <small>Contacts</small> </a>
                </li>
                <li><a href="#" class="messages">Messages
					(10) <small>Messages</small> </a>
                </li>
                <li><a href="#" class="playlist">Play
					List <small>Play List</small> </a>
                </li>
                <li><a href="#" class="videos">Videos
                        <small>Videos</small> </a>
                </li>
                <li><input type="button"
                           id="NotificationBTN" value="Show notifications popup "
                           onclick="javascript:showNotificationsNotification()" />
                </li>
                <li id="alertpanel"><a href="#" onClick="javascript:showNotificationsID()" class="alerts">Alerts</a>
                    <div  id="notificationS" class="subpanel"  >

                    </div>
                </li>
                <li id="chatpanel"><a href="#" class="chat" onClick="javascript:updateList()">Friends (<strong>18</strong>)
                    </a>
                    <div class="subpanel">
                        <h3>
                            <span>&ndash; </span>Friends Online
                        </h3>
                        <ul>
                            <li><span>Family Members</span>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><span>Other Friends</span>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                            <li><a href="#"><img
                                        src="../../../public/images/chat-thumb.gif"
                                        alt="" /> Your Friend</a>
                            </li>
                        </ul>
                    </div>
                </li>
            </ul>
        </div>
        <div id="two" class="jGrowl bottom-left">
            <div class="jGrowl-notification"></div>
        </div>
        <!-- Notification bar  end here -->
        <div id="footer">
            <p>&copy; Megasoft 2011. Website Design by alot of PPL isA</p>
        </div>
        <script type="text/javascript">
            function validate_formMain() {
                valid = true;

                if (document.searchFormMain.searchMain.value == "") {
                    alert("Please fill in the word to search for");
                    valid = false;
                }

                return valid;
            }
        </script>


    </body>
</html>
